package com.all.play.mynavigationview;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.BaseTransientBottomBar;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);

    }


    public void showToast(View view){
        //Toast.makeText(MainActivity.this, "test", Toast.LENGTH_SHORT).show();


        Toast result = new Toast(this);

        LayoutInflater inflate = (LayoutInflater)
                this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflate.inflate(R.layout.custom_toast, null);
        TextView tv = (TextView)v.findViewById(R.id.tv_toast);
        tv.setText("test~~~test");

        result.setView(v);
        result.setDuration(Toast.LENGTH_LONG);
        result.setGravity(Gravity.CENTER,0,0);
        result.show();
    }


    public void showSnackBar(View view){

        Snackbar snackbar = Snackbar.make(view, "snackbar 打开?", 10000);
        snackbar.setAction("确定", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showToast(null);
            }
        });

        //不能设置多个Action,设置多个,会被最后一个覆盖
//        snackbar.setAction("取消", new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showToast(null);
//            }
//        });

        snackbar.addCallback(new BaseTransientBottomBar.BaseCallback<Snackbar>() {
            @Override
            public void onDismissed(Snackbar transientBottomBar, int event) {
                Toast.makeText(MainActivity.this, "onDissMiss", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onShown(Snackbar transientBottomBar) {
                Toast.makeText(MainActivity.this, "onshow", Toast.LENGTH_SHORT).show();
            }
        });

        snackbar.setActionTextColor(Color.BLUE);

        snackbar.show();


    }
}
